from lxml import etree

'''
<book>
    <id>1</id>
    <name>野花遍地香</name>
    <price>1.23</price>
    <author>
        <nick>周大强</nick>
        <nick>周芷若</nick>
    </author>
</book>
'''

xml = '''
<book>
    <id>1</id>
    <name>野花遍地香</name>
    <price>1.23</price>
    <nick>臭豆腐</nick>
    <author>
        <nick id='10086'>周大强</nick>
        <nick id='10010'>周芷若</nick>
        <nick class='joy'>周杰伦</nick>
        <nick class='eason'>蔡依林</nick>
        <div>
            <nick>生活</nick>
        </div>
        <span>
            <nick>欺骗</nick>
        </span>
    </author>
    
    <partner>
        <nick id='ppc'>胖胖陈</nick>
        <nick id='xp'>小胖</nick>
    </partner>      
</book>
'''

tree = etree.XML(xml)
# result = tree.xpath('/book/name/text()') # text() 拿文本
# result = tree.xpath('/book/author//nick/text()')  # // 后代
# result = tree.xpath('/book/author/*/nick/text()')  # * 任意的节点 通配符
result = tree.xpath('/book//nick/text()')
print(result)


